package com.lj.universalframework.ui.activity

import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.lj.universalframework.R
import com.lj.universalframework.adapter.ItemAdapter
import com.lj.universalframework.databinding.ActivityMain2Binding
import com.lj.universalframework.ui.BaseActivity
import com.lj.universalframework.ui.viewModel.Main2ViewModel
import com.lj.universalframework.utils.loadRefresh
import kotlinx.android.synthetic.main.activity_main2.*

class MainActivity2 : BaseActivity<Main2ViewModel, ActivityMain2Binding>() {

    lateinit var itemAdapter: ItemAdapter

    override fun initView() {
        super.initView()

        mDataBinding.recycler.layoutManager = LinearLayoutManager(this)
        itemAdapter = ItemAdapter()
        mDataBinding.recycler.adapter = itemAdapter

        abnormal_state_view.modifyStatus(3)

        refreshLayout.apply {
            //开启自动加载功能（非必须)
            setEnableAutoLoadMore(false)
            //是否启用越界拖动（仿苹果效果）1.0.4-6
            setEnableOverScrollDrag(true)
            setOnRefreshListener {
                //在刷新监听器上设置
            }
            setOnLoadMoreListener {
                //加载更多侦听器
            }
            //显示刷新动画并且触发刷新事件
            //autoRefresh()
        }
        mViewModel.datas.observe(this, Observer {
            itemAdapter.refreshData(it)
        })
    }

    override fun initData() {
        //获取数据
        mViewModel.getOrderByPhone()
    }
}